import { getTeacherList } from '@/services/ant-design-pro/teacher';
import type { ProColumns } from '@ant-design/pro-table';
import ProTable from '@ant-design/pro-table';
import { Button } from 'antd';
import React from 'react';
import type { IRouteComponentProps } from 'umi';
import { tableColumns } from './config';

export default function TeacherList({ history }: IRouteComponentProps) {
  const newTableColumns: ProColumns<any>[] = [
    ...tableColumns,
    {
      key: 'options',
      title: '操作',
      search: false,
      render() {
        return [
          <Button type="link" key="edit">
            编辑
          </Button>,
          <Button type="link" key="delete">
            删除
          </Button>,
        ];
      },
    },
  ];
  const toSave = () => {
    history.push({
      pathname: '/teacher/save',
    });
  };
  const handleFetchData = async (params: any) => {
    const { results = [] }: any = await getTeacherList(params);
    console.log('请求教师列表 --> ', results);

    return {
      data: results,
    };
  };
  return (
    <ProTable
      columns={newTableColumns}
      cardBordered
      options={false}
      request={handleFetchData}
      rowKey="id"
      toolBarRender={() => [
        <Button type="primary" key="add" onClick={toSave}>
          新增
        </Button>,
      ]}
    />
  );
}
